package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {


    /**
     * 新建订单
     * @param orders
     */
    void insert(Orders orders);


    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    /**
     * 分页查询历史订单
     * @param ordersPageQueryDTO
     * @return
     */

    Page<Orders> list(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 通过id查询订单详情
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /**
     * 统计各个状态的数量
     * @param status
     * @return
     */
    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> selectByStatusAndTime(Integer status, LocalDateTime time);

    /**
     * 统计营业额
     * @param map
     * @return
     */
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{beginTime} and #{endTime}")
    Double selectByMap(Map map);

    /**
     * 统计
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     *
     * @param beginTime
     * @param endTime
     * @param status
     * @return
     */
    List<GoodsSalesDTO> selectTop10(LocalDate beginTime, LocalDate endTime, Integer status);
}
